///////////////////////////////////////////////////////////////////////////////
// File Name:   vga_ctrl.v
//
// Author:      Cody Cziesler
//
// Description: The top-level control block for the vga
//
///////////////////////////////////////////////////////////////////////////////

module vga_get_colors (
  input  wire        blank,          // When high, output 8'h0

  input  wire        border_en,      // When high, output a border
  input  wire  [7:0] border_color,   // The border color in RGB
  input  wire  [7:0] border_width,   // The border width

  input  wire  [7:0] bg_color,       // The background color
  
  input  wire  [10:0] x_pixel,
  input  wire  [10:0] y_pixel,
  output wire  [2:0] red,
  output wire  [2:0] green,
  output wire  [1:0] blue
);

parameter COLS = 10'd640;
parameter ROWS = 10'd480;

wire in_border;

//-----------------------------------------------------------------------------
// Registers to hold the outputted pixel data - we don't want to read outputs
//-----------------------------------------------------------------------------
reg [2:0] red_r;
reg [2:0] green_r;
reg [1:0] blue_r;

//-----------------------------------------------------------------------------
// Assign the outputted pixel data to the regs
//-----------------------------------------------------------------------------
assign red[2:0]   = (blank == 1'b1) ? 3'b000 : red_r[2:0];
assign green[2:0] = (blank == 1'b1) ? 3'b000 : green_r[2:0];
assign blue[1:0]  = (blank == 1'b1) ? 2'b00  : blue_r[1:0];

//-----------------------------------------------------------------------------
// High when the pixel (x_pixel,y_pixel) is within the border specified by
//   border_width and border_en is high
//-----------------------------------------------------------------------------
assign in_border = (border_en == 1'b1 && (x_pixel < border_width || x_pixel > (COLS - border_width) || y_pixel < border_width || y_pixel > (ROWS - border_width))) ? 1'b1 : 1'b0;

//-----------------------------------------------------------------------------
// Set the pixel data based on the options 
//-----------------------------------------------------------------------------
always @(*) begin
  if (in_border == 1'b1) begin
    red_r   = border_color[7:5];
    green_r = border_color[4:2];
    blue_r  = border_color[1:0];
  end else begin
    red_r   = bg_color[7:5];
    green_r = bg_color[4:2];
    blue_r  = bg_color[1:0];
  end
end

endmodule
